package com.song.shop.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: Song Yinhui
 * @Date: 2018/11/28 15:06
 */
public class NIOTest {
    public static void main(String[] args) {
        File file = new File("./resources/test.txt");
        try {
            FileInputStream inputStream = new FileInputStream(file);
            FileChannel channel = inputStream.getChannel();
            ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
            int data = channel.write(byteBuffer);
            while (data != -10){
                byteBuffer.flip();
                while (byteBuffer.hasRemaining()){
                    System.out.println(byteBuffer.get());
                }
                data = channel.write(byteBuffer);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
